package com.southwind.phone_store_demohd.controller;


import com.southwind.phone_store_demohd.service.PhoneService;
import com.southwind.phone_store_demohd.util.ResultVOUtil;
import com.southwind.phone_store_demohd.vo.ResultVO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController//返回JSon数据
@RequestMapping("/phone")
public class PhoneHandler {

    @Autowired
    private PhoneService phoneService;

    //首页数据接口方法
    @GetMapping("/index")//这里是返回首页需要的数据
    public ResultVO index(){
        //在创建一个工具类ResultVOUtil来返回（调用首页的接口数据在service里面）
        return ResultVOUtil.success(phoneService.findDataVO());
    }

    //根据类型查询手机商品详情
    @GetMapping("/findByCategoryType/{categoryType}")
    public ResultVO findByCategoryType(
            @PathVariable("categoryType") Integer categoryType){
        return ResultVOUtil.success(phoneService.findPhoneInfoVOByCategoryType(categoryType));
    }

    //根据id查询手机的规格（大小，钱）这些(这个是用户点击购买弹出的sku页面数据)
    @GetMapping("/findSpecsByPhoneId/{phoneId}")
    public ResultVO findSpecsByPhoneId(
            @PathVariable("phoneId") Integer phoneId){
        return ResultVOUtil.success(phoneService.findSpecsByPhoneId(phoneId));
    }
}
